//成都眼科调用眼部信息检查

// 数据接口
function getEyeDataFromOther(){
	var def = $.Deferred();
	var url_ = "https://eyerecord.healthsvision.com/health_records/get_record_by_phone";
	var url = rootUrl+"/basicinformationquery/sendHttpQuest";
	var phone = $("#patient_phone").text().trim();
	var params = {};
	params.phone = phone;
	params.url = url_;
	$.ajax({
		url: url,
		data : {params:JSON.stringify(params)},
		dataType: "json",
		type : "get",
		crossDomain: true,
		success : function(data) {
			if(data.description=='成功'){
				def.resolve(data);
			}else{
				def.reject();
			}
		},
		error: function (xhr, textStatus) {
			def.reject();
		},
	});
	return def.promise();
}


//调用数据接口，表格展示
function getDataToTable(){
	debugger;
	var phone = $("#patient_phone").text().trim();
	if(phone != '--'){
		$.when(
			getEyeDataFromOther()
	    ).done(function (data) {
	   	 //表格展示
	    	eyeInitTable(data);
	    });
	}else{
//		layer.alert("该病人没有电话号码！无法查询眼部信息；")
	}
}

function eyeInitTable(data){
	
//	  var data = {"code":0,"description":"成功","patient":{"name":"罗林","identity_card":"51192219**********"},
//			      "items":{"yuanshi_luoyan_shili_right":"0.8","yuanshi_luoyan_shili_left":"0.8","yuanshi_daijing_shili_right":"0.8","yuanshi_daiji ng_shili_left":"0.8","yan_ya_right":"1","yan_ya_left":"1","yi_zhu":"医学验光配镜\r\n"},
//			  "drs_images_right":["http://hs-devtest.oss-cn-hangzhou.aliyuncs.com/health_record/17/2c2d3c0c4a7d4aa5a6d84920243e8202"],
//			  "drs_images_left":["http://hs-devtest.oss-cn-hangzhou.aliyuncs.com/health_record/17/b044397431f64e30985ee6a5750ee26f"],
//			  "liexideng_images_right":["http://hs-devtest.oss-cn-hangzhou.aliyuncs.com/health_record/17/f5f370341eb24a0ab404dcfe10305087"],
//			  "liexideng_images_left":["http://hs-devtest.oss-cn-hangzhou.aliyuncs.com/health_record/17/04b19412ba00408d817454d0e91d4119"]}
	  var patient = data.patient; 
	  var eyeArr = [{name:"右眼的眼底照",value:(data.drs_images_right).join("||")},
	                {name:"左眼的眼底照",value:(data.drs_images_left).join("||")},
		  			{name:"右眼的裂隙灯照",value:(data.liexideng_images_right).join("||")},
	                {name:" 左眼的裂隙灯照",value:(data.liexideng_images_left).join("||")}];
	  var tableId= "check-report-table";
	  $("#" + tableId).find(".no-data").hide();
	  for(var i =0;i<eyeArr.length;i++){
		  var ids = jQuery("#" + tableId).jqGrid('getDataIDs');
		  var dataRow =
		  {
				  'PAA07' : patient.name,
				  'BHF03' : '',
				  'PAA06' : '',
				  'PAA43' : eyeArr[i].name,
				  'BFC03' : '',
				  'PAB11' : '',
				  'PAA46' : '',
				  'vtAllPath' : eyeArr[i].value,
				  'vtPath' : '',
				  'PAA01' : '',
		  };
		  // 将新添加的行插入到第一列
		  $("#" + tableId).jqGrid("addRowData", (ids.length + 1), dataRow, "last");
	  }
}





